//
//  LXCommissionHeaderView.m
//  绿稀全球购
//
//  Created by 王敏 on 16/6/10.
//  Copyright © 2016年 SJT. All rights reserved.
//

#import "LXCommissionHeaderView.h"


#import "LXWithdrawController.h"

@interface LXCommissionHeaderView()

/**
 *  立即提现
 */
@property(nonatomic,strong)UIButton * withdrawals;

/**
 *  佣金
 */
@property(nonatomic,strong)UILabel * commissionLabel;

/**
 *  背景图片
 */
@property(nonatomic,strong)UIImageView * backgroungImageView;
@end

@implementation LXCommissionHeaderView

-(id)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        UIButton * button = [[UIButton alloc] initWithFrame:CGRectZero];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        button.backgroundColor = [UIColor clearColor];
        
        [button setTitle:@"立即提现" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
//        [button setImage:[UIImage imageNamed:@"small_back_data_icon"] forState:UIControlStateNormal];
//       
        self.withdrawals = button;
        
        
        UILabel * label = [[UILabel alloc] initWithFrame:CGRectZero];
        label.backgroundColor = [UIColor clearColor];
        label.font = [UIFont systemFontOfSize:40];
        label.textColor = [UIColor whiteColor];
        label.textAlignment = NSTextAlignmentCenter;
        [self addSubview:label];
        self.commissionLabel = label;
        
        
        UIImageView * imgv = [[UIImageView alloc] initWithFrame:self.bounds];
        imgv.image = [UIImage imageNamed:@"brokerage_bg01"];
        [self addSubview:imgv];
        [self sendSubviewToBack:imgv];
        imgv.userInteractionEnabled = YES;
        self.backgroungImageView = imgv;
        
        self.commission = 0;
         [self.backgroungImageView addSubview:button];
        
    }
    return self;
}



-(void)layoutSubviews{
    [super layoutSubviews];
    self.withdrawals.size = [self.withdrawals.currentTitle sizeInAre:MaxSize font:self.withdrawals.titleLabel.font];
    self.withdrawals.x = self.width-self.withdrawals.width - globalMargin;
    self.withdrawals.y = 10;
    
    self.withdrawals.imageEdgeInsets = UIEdgeInsetsMake(0,self.withdrawals.width-20,0,-(self.withdrawals.width-20));
    
    self.withdrawals.titleEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 15);
    
    self.commissionLabel.width = self.width;
    self.commissionLabel.height = 60;
    self.commissionLabel.x = 0;
    self.commissionLabel.centerY = self.height/2.0;
}

-(void)setCommission:(CGFloat)commission{
    _commission = commission;
    if(commission == 0){
        self.commissionLabel.text = @"暂无佣金";
    }else{
        self.commissionLabel.text = [NSString stringWithFormat:@"%.2f",commission];
    }
}


-(void)buttonClick:(UIButton*)button{
    LXWithdrawController * vc = [[LXWithdrawController alloc] init];
    [[self getCurrentVC].navigationController pushViewController:vc animated:YES];
}

@end
